﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Utility
{
    public static class HttpContentType
    {
        /// <summary>
        /// 资源类型：普通文本
        /// </summary>
        public const string text_plain = "text/plain";

        /// <summary>
        /// 资源类型：普通xml
        /// </summary>
        public const string text_xml = " text/xml";

        /// <summary>
        /// 资源类型：json字符串
        /// </summary>
        public const string application_json = "application/json";

        /// <summary>
        /// 资源类型：未知类型(数据流)
        /// </summary>
        public const string application_octet_stream = "application/octet-stream";

        /// <summary>
        /// 资源类型：表单数据(键值对)
        /// </summary>
        public const string www_form_urlencoded = "application/x-www-form-urlencoded";

        /// <summary>
        /// 资源类型：表单数据(键值对)。编码方式为 gb2312
        /// </summary>
        public const string www_form_urlencoded_gb2312 = "application/x-www-form-urlencoded;charset=gb2312";

        /// <summary>
        /// 资源类型：表单数据(键值对)。编码方式为 utf-8
        /// </summary>
        public const string www_form_urlencoded_utf8 = "application/x-www-form-urlencoded;charset=utf-8";

        /// <summary>
        /// 资源类型：多分部数据
        /// </summary>
        public const string multipart_form_data = "multipart/form-data";

        public static void ContentType(ref string contenttype)
        {
            switch (contenttype)
            {
                case "1":
                    contenttype = text_plain;
                    break;
                case "2":
                    contenttype = text_xml;
                    break;
                case "3":
                    contenttype = application_json;
                    break;
                case "4":
                    contenttype = www_form_urlencoded;
                    break;
                case "5":
                    contenttype = www_form_urlencoded_utf8;
                    break;
                default:
                    contenttype = application_json;
                    break;
            }
        }
    }
}
